home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / stdlib / RCS / MemChunkAlloc.c,v < prev    next >
Encoding:
Text File  |  1991-12-03  |  6.5 KB  |  258 lines

  1. head     1.4;
  2. branch   ;
  3. access   ;
  4. symbols  sprited:1.4.1;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.4
  10. date     90.09.27.04.42.29;  author rab;  state Exp;
  11. branches 1.4.1.1;
  12. next     1.3;
  13.  
  14. 1.3
  15. date     88.06.18.17.17.24;  author ouster;  state Exp;
  16. branches ;
  17. next     1.2;
  18.  
  19. 1.2
  20. date     88.05.21.11.49.05;  author ouster;  state Exp;
  21. branches ;
  22. next     1.1;
  23.  
  24. 1.1
  25. date     88.05.20.15.49.12;  author ouster;  state Exp;
  26. branches ;
  27. next     ;
  28.  
  29. 1.4.1.1
  30. date     91.12.02.20.35.10;  author kupfer;  state Exp;
  31. branches ;
  32. next     ;
  33.  
  34.  
  35. desc
  36. @@
  37.  
  38.  
  39. 1.4
  40. log
  41. @Fixed MemChunkAlloc to handle misaligned addresses returned by sbrk.
  42. @
  43. text
  44. @/* 
  45.  * MemChunkAlloc.c --
  46.  *
  47.  *    Source code for the "MemChunkAlloc" procedure, which is used
  48.  *    internally by the memory allocator to create new memory for
  49.  *    user-level programs.  Different programs or uses of the
  50.  *    allocator may replace this version of MemChunkAlloc with
  51.  *    something appropriate to the particular program.  See memInt.h
  52.  *    for overall information about how the allocator works.
  53.  *
  54.  * Copyright 1985, 1988 Regents of the University of California
  55.  * Permission to use, copy, modify, and distribute this
  56.  * software and its documentation for any purpose and without
  57.  * fee is hereby granted, provided that the above copyright
  58.  * notice appear in all copies.  The University of California
  59.  * makes no representations about the suitability of this
  60.  * software for any purpose.  It is provided "as is" without
  61.  * express or implied warranty.
  62.  */
  63.  
  64. #ifndef lint
  65. static char rcsid[] = "$Header: /sprite/src/lib/c/stdlib/RCS/MemChunkAlloc.c,v 1.3 88/06/18 17:17:24 ouster Exp Locker: rab $ SPRITE (Berkeley)";
  66. #endif not lint
  67.  
  68. #include "memInt.h"
  69. #include <stdio.h>
  70. #include <sys/types.h>
  71.  
  72. /*
  73.  * UNIX library imports:
  74.  */
  75.  
  76. extern caddr_t    sbrk();
  77.  
  78. /*
  79.  * The variables below don't exactly belong in this file, but they
  80.  * need to be someplace that's use-dependent (just like MemChunkAlloc)
  81.  * so that they can be initialized differently for different uses
  82.  * of the allocator (e.g. kernel vs. user).
  83.  */
  84.  
  85. extern int    fprintf();
  86. int        (*memPrintProc)()    = fprintf;
  87. ClientData    memPrintData        = (ClientData) stdout;
  88.  
  89. /*
  90.  *----------------------------------------------------------------------
  91.  *
  92.  * MemChunkAlloc --
  93.  *
  94.  *    malloc calls this procedure to get another region of storage
  95.  *    from the system (i.e. whenever the storage it's gotten so far
  96.  *    is insufficient to meet a request).  The actual size returned 
  97.  *    may be greater than size but not less.  This region now becomes 
  98.  *    the permanent property of malloc, and will never be returned.  
  99.  *
  100.  * Results:
  101.  *    The return value is a pointer to a new block of memory that
  102.  *    is size bytes long.
  103.  *
  104.  * Side effects:
  105.  *    The virtual address space of the process is extended.
  106.  *    If the VAS can't be increased, the process is terminated.
  107.  *
  108.  *----------------------------------------------------------------------
  109.  */
  110.  
  111. Address
  112. MemChunkAlloc(size)
  113.     int size;            /* Number of bytes desired.  */
  114. {
  115.     Address result;
  116.     int misAlignment;
  117.  
  118.     result = (Address) sbrk(size);
  119.     if (result == (Address) -1) {
  120.     panic("MemChunkAlloc couldn't extend heap");
  121.     return(0);        /* should never get here */
  122.     }
  123.     /* Make sure `result' is aligned to hold at least a double */
  124.     if ((misAlignment = (int) result & 7) != 0) {
  125.     result += 8 - misAlignment;
  126.     (Address) sbrk(8 - misAlignment);
  127.     }
  128.     return result;
  129. }
  130. @
  131.  
  132.  
  133. 1.4.1.1
  134. log
  135. @Initial branch for Sprite server.
  136. @
  137. text
  138. @d22 1
  139. a22 1
  140. static char rcsid[] = "$Header: /sprite/src/lib/c/stdlib/RCS/MemChunkAlloc.c,v 1.4 90/09/27 04:42:29 rab Exp $ SPRITE (Berkeley)";
  141. @
  142.  
  143.  
  144. 1.3
  145. log
  146. @Use panic instead of Sys_Panic.
  147. @
  148. text
  149. @d22 1
  150. a22 1
  151. static char rcsid[] = "$Header: MemChunkAlloc.c,v 1.2 88/05/21 11:49:05 ouster Exp $ SPRITE (Berkeley)";
  152. d73 1
  153. d79 5
  154. @
  155.  
  156.  
  157. 1.2
  158. log
  159. @Change to use sbrk.
  160. @
  161. text
  162. @d22 1
  163. a22 1
  164. static char rcsid[] = "$Header: MemChunkAlloc.c,v 1.1 88/05/20 15:49:12 ouster Exp $ SPRITE (Berkeley)";
  165. d76 1
  166. a76 1
  167.     MemPanic("MemChunkAlloc couldn't extend heap");
  168. @
  169.  
  170.  
  171. 1.1
  172. log
  173. @Initial revision
  174. @
  175. text
  176. @d22 1
  177. a22 1
  178. static char rcsid[] = "$Header: proto.c,v 1.2 88/03/11 08:39:08 ouster Exp $ SPRITE (Berkeley)";
  179. a25 1
  180. #include "vm.h"
  181. d27 1
  182. d30 1
  183. a30 4
  184.  * NextAddr is the location of the first as-yet-unallocated byte in
  185.  * the heap.  It's used by MemCunkAlloc to increase the heap size
  186.  * and to emulate brk and sbrk.  PageSize is really the size of a
  187.  * memory page minus 1.
  188. d33 1
  189. a33 2
  190. static Address nextAddr;
  191. static int pageSize;
  192. a35 7
  193.  * Macro to compute for any address, the first addresss of the page
  194.  * it is on.
  195.  */
  196.  
  197. #define FirstAddrOnPage(address)  (((int) (address)) & (~pageSize))
  198.  
  199. /*
  200. d51 1
  201. a51 1
  202.  *    malloc will call MemChunkAlloc to get another region of storage
  203. a71 1
  204.     ReturnStatus status;
  205. a72 3
  206.     extern int end;        /* Symbol defined by loader to be the first
  207.                  * location above all data. */
  208.     static Boolean initialized = FALSE;
  209. d74 4
  210. a77 15
  211.     if (!initialized) {
  212.         initialized = TRUE;
  213.  
  214.     /*
  215.      *  Get the system page size and calculate the address in the heap 
  216.      *  after the end of data to start allocating chunks from.
  217.      */
  218.     
  219.     if (Vm_PageSize(&pageSize) != SUCCESS) {
  220.         MemPanic("Mem ChunkInit: failed to get page size");
  221.         return;        /* should never get here */
  222.     }
  223.     pageSize -= 1;
  224.     
  225.     nextAddr = (Address) &end;
  226. a78 21
  227.  
  228.     /*
  229.      * Check to see if the request is already on a page that is mapped so
  230.      * we can avoid a system call.
  231.      *
  232.      * If the starting address of the request is on the same page as
  233.      * the ending address, then the requested block is already mapped
  234.      * and the system call can be avoided.
  235.      */
  236.  
  237.     if(FirstAddrOnPage(nextAddr - 1) != FirstAddrOnPage(nextAddr + size)) {
  238.     status = Vm_CreateVA(nextAddr, size);
  239.     if (status != SUCCESS) {
  240.         MemPanic("MemChunkAlloc: failed to create VA");
  241.         return(0);    /* should never get here */
  242.     }
  243.     }
  244.  
  245.     result = nextAddr;
  246.     nextAddr   += size;
  247.  
  248. a79 32
  249. }
  250.  
  251. /*
  252.  *----------------------------------------------------------------------
  253.  *
  254.  !<arch>
  255. __.SYMDEF       595480750   341   155   100664  182       `
  256. 8··#·/·@·Q·d·v_Cmd_BindingGet_Cmd_BindingCreate_Cmd_MapKey_Cmd_TableDelete_Cmd_TableCreate_Cmd_BindingDelete_Cmd_EnumBindingscmdPub.o        595468692   341   155   100664  1501      `
  257. dL┤áNVHτ  Hx a    ≥$@BÇXOB▓ RÇt┤Çl⌠B¬Hxa    ╥"%At%B 
  258. Lε °N^NuNVHτ 8(nBé&t,Jïg /E∙NÆ/+NÆ/ NÆ▐ⁿ &k JïfαRér▓él╨/,E∙NÆ/ NÆLε ≡N^NuNV ⁿHτ0<(n &.-n ⁿI┬"n ⁿ*q,JìgF/ /a    ,POJÇf./-a    /a     @Hha    +@//a   ■·`^*m Jìf║HxE∙NÆ*@/ G∙Nô+@"@RI/    NÆ